Skip to content

Improve types on AssetIssuance struct#289

Open
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-07/issance-typing
Open

Improve types on AssetIssuance struct#289
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-07/issance-typing

Conversation

@apoelstra

Copy link
Copy Markdown
Member

Use strong types for asset entropy and blinding nonce.

…nonce

Previously we had been using the secp265k1_zkp::Tweak type to represent
a blinding nonce in an issuance. This had a number of issues:

* `Tweak` is a low-level crypto type which is ambiguous about whether or
   not it's secret or public, and doesn't have any meaning beyond "value
   you can add to a secp point"
* In particular the special `ZERO_TWEAK` constant was interpreted to
  mean "new issuance" and this was implicit throughout the codebase.
* As a foreign type, we could not directly implement any encoding or
  decoding traits on this; we had to convert it to/from a byte array.
* As a "general" type, it doesn't distinguish between various uses of
  tweak, which can lead to dangerous type confusion.
* `Tweak` cannot represent values that are out of range of the secp256k1
  group, while technically Elements permits such transactions to exist
  (e.g. `decoderawtransaction` will accept them), even though it will
  fail VerifyAmounts. (I carefully checked all the codepaths: if the
  amounts in an issuance are null, so much be the nonce (or else you get
  a "superfluous issuance" error; if they're non-null and the blinding
  nonce is zero (which is in-range), it's a new issuance; if it's not
  zero then it's put into secp256k1_generator_generate_blinded which
  checks for overflow as its very first check.)
The only place this is actually "consensus encoded" is arguably in the
pegin witness stack, but that's reason enough to have these.
@apoelstra

Copy link
Copy Markdown
Member Author

I think after this we should cut a 0.27 release of rust-elements. I have a bunch of breakage related to encoding coming down the pike and it'd be good to have a release right before and after that to try to contain the damage for people updating their stuff.

@philipr-za philipr-za left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good and principled. Tests pass locally, ACK 02122be.

Some minor editorial comments.

Comment thread src/issuance.rs
@@ -1,4 +1,4 @@
// Rust Elements Library
// Rust Elements Libraryss

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
// Rust Elements Libraryss
// Rust Elements Librarys

Comment thread src/issuance.rs
}

encoding::encoder_newtype_exact! {
/// Encoder for the [`OutPoint`] type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Encoder for the [`OutPoint`] type.
/// Encoder for the [`AssetEntropy`] type.

Comment thread src/issuance.rs
}

encoding::encoder_newtype_exact! {
/// Encoder for the [`OutPoint`] type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Encoder for the [`OutPoint`] type.
/// Encoder for the [`AssetBlindingNonce`] type.

Comment thread src/issuance.rs
}

encoding::encoder_newtype_exact! {
/// Encoder for the [`OutPoint`] type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Encoder for the [`OutPoint`] type.
/// Encoder for the [`AssetId`] type.

Comment thread src/transaction/mod.rs

use crate::{encode::serialize, pset::PartiallySignedTransaction};
use crate::issuance::AssetBlindingNonce;
use crate::{encode::serialize, pset::PartiallySignedTransaction};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use crate::{encode::serialize, pset::PartiallySignedTransaction};
use crate::{encode::serialize, pset::PartiallySignedTransaction};

indenting

Comment thread src/issuance.rs
/// used to blind the reissuance token (which must be blinded in order to be
/// spent, due to a quirk in the Elements consensus code.)
///
/// Conceputally this can be thought of as an `Option<AssetBlindingFactor>`, except

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Conceputally this can be thought of as an `Option<AssetBlindingFactor>`, except
/// Conceptually this can be thought of as an `Option<AssetBlindingFactor>`, except

@delta1 delta1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 02122be; tested locally

Minor nits can be fixed now or in follow-up if you prefer

Comment thread src/transaction/mod.rs
use std::str::FromStr;

use crate::{encode::serialize, pset::PartiallySignedTransaction};
use crate::issuance::AssetBlindingNonce;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary since super::* is imported below

Comment thread src/issuance.rs
/// This is something of a dangerous function, since in general blinding factors should
/// be considered secret data, while blinding nonces are public (they are encoded on
/// the blockchain). So callers of this function should be sure that this is a blinding
/// factor that they intend to reveal.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// factor that they intend to reveal.)
/// factor that they intend to reveal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants